<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <script>
                function title() {
                    document.getElementById('admin').className='selected';
                }
                window.onload=title;
            </script>
            <h:form id="conForm" enctype="multipart/form-data">
                <h1 class="title">
                    <a href="#" class="back" onclick="history.go(-1)"/>
                    Relatório Convênio
                </h1>
                <p:messages id="messages" showDetail="true" autoUpdate="true"  /> 
                <div class="row">
                    <div class="twelve columns"> 
                        <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Pesquisar</h4></legend>
                            <p:panel id="ConvenioPanel" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix ">

                                <p:outputLabel value="Convênio:" styleClass="grid_3" />
                                <p:autoComplete value="#{managerSearchProcedure.searchOperator}" 
                                                panelStyle="max-height: 200px;" 
                                                completeMethod="#{managerSearchProcedure.autocomplete}"  
                                                var="p" itemLabel="#{p.name}" itemValue="#{p}" forceSelection="true"
                                                styleClass="grid_10" dropdown="true" 
                                                converter="#{autocompleteconverter}" >  

                                </p:autoComplete>

                            </p:panel>

                        

                        <div class="buttonAction">
                            <p:commandButton value="Pesquisar" icon="ui-icon-search"
                                             process="@form" update="@form"
                                             actionListener="#{managerSearchProcedure.pesquisarValoresProcedimento()}"
                                             styleClass="ui-priority-primary" />


                            <p:button href="indexprocedure.xhtml" value="Cancelar"  icon="ui-icon-trash" />
                        </div >

                        <br/>

                        <p:commandButton value="Imprimir" icon="ui-icon-print"
                                         process="@this"
                                         ajax="false"  
                                         onclick="this.form.target='_blank'"
                                         actionListener="#{managerSearchProcedure.relProcedure()}"
                                         styleClass="ui-priority-primary right" />
                        <div class="clear"/>
                        <p:dataTable id="tableEntrada" var="in" value="#{managerSearchProcedure.voProcedureValues}" 
                                     selection="#{managerSearchProcedure.selectVoProcedureValues}"
                                     emptyMessage="Nenhum registro" paginator="true" rows="10"
                                     rowIndexVar="rowid"
                                     rowKey="#{in.id}" >


                            <p:column selectionMode="multiple" width="10"/>

                            <p:column headerText="Código" style="white-space: pre-wrap;" width="200">  
                                <h:outputText value="#{in.cod}"/>
                            </p:column>  

                            <p:column headerText="Procedimento" style="white-space: pre-wrap; ">  
                                <h:outputText value="#{in.name}"/>
                            </p:column>

                            <p:column headerText="Valor" style="white-space: pre-wrap; ">  
                                <h:outputText value="#{in.amount}"/>
                            </p:column>

                            <p:column headerText="Ações" width="55">

                                <p:commandButton title="Remover Procedimento"
                                                 rendered="false"
                                                 styleClass="right" icon="ui-icon-closethick"
                                                 update="@this" process="@this"/>

                                <p:commandButton title="Alterar Valor" 
                                                 styleClass="right" icon="ui-icon-pencil"
                                                 onclick="dlgAlterValue.show();"
                                                 actionListener="#{managerSearchProcedure.loadValue(rowid)}"
                                                 update="@this, :conForm:panelAlterValue" process="@this"/>

                            </p:column>

                        </p:dataTable>
                        
                        </fieldset>

                        <p:dialog id="dlgAlterValue"  widgetVar="dlgAlterValue"
                                  header="Alterar valor do procedimento" modal="true"
                                  width="700" closeOnEscape="true"  dynamic="true" > 

                            <p:ajax event="close" update="@form" />
                            <p:messages autoUpdate="true" />
                            <p:panel id="panelAlterValue" style="background: none; width: 97%;" 
                                     styleClass="container_24 clearfix " >

                                <p:outputLabel value="Valor Total: " styleClass="grid_4" />
                                <p:inputText value="#{managerSearchProcedure.newValue}" 
                                             styleClass="grid_5" onkeypress="jQuery(this).autoNumeric({aSign:'R$ ',aSep: '.', aDec: ','} );">
                                    <f:convertNumber type="currency" locale="pt,BR"/>
                                </p:inputText>

                                <div class="clear"/>
                                <div class="buttonAction">
                                    <p:commandButton value="Atualizar"
                                                     icon="ui-icon-disk"
                                                     actionListener="#{managerSearchProcedure.alterValueProcedure()}"
                                                     update="@this, :conForm:panelAlterValue" 
                                                     process="@this, :conForm:panelAlterValue"/>
                                </div>


                            </p:panel>
                        </p:dialog>

                        <br/>



                    </div>

                </div>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
